﻿<UserControl x:Class="SubtitleTools.Shell.Logs"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:conv="clr-namespace:SubtitleTools.Common.Converters;assembly=SubtitleTools.Common"
             xmlns:vm="clr-namespace:SubtitleTools.Infrastructure.ViewModels;assembly=SubtitleTools.Infrastructure"
             xmlns:b="clr-namespace:SubtitleTools.Common.Behaviors;assembly=SubtitleTools.Common"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <UserControl.Resources>
        <vm:LogsViewModel x:Key="vmLogsViewModel" />
        <conv:ImageConverter x:Key="convImageConverter" />
        <conv:ColorConverter x:Key="convColorConverter" />

        <DataTemplate x:Key="col1">
            <StackPanel>
                <Image Source="{Binding Type, Converter={StaticResource convImageConverter}}" />
            </StackPanel>
        </DataTemplate>

        <DataTemplate x:Key="col2">
            <StackPanel >
                <TextBlock  Text="{Binding Time, StringFormat={}{0:MM/dd/yyyy hh:mm:ss.ff}}" />
            </StackPanel>
        </DataTemplate>

        <DataTemplate x:Key="col3">
            <StackPanel>
                <TextBlock Foreground="{Binding Type, Converter={StaticResource convColorConverter}}" 
                           Text="{Binding Message}" />
            </StackPanel>
        </DataTemplate>
    </UserControl.Resources>
    <Grid DataContext="{Binding Source={StaticResource vmLogsViewModel}}">
        <ListView 
            b:AutoScrollListView.AutoScroll="True"   
            SelectedItem="{Binding SelectedItem}"
            ItemsSource="{Binding LogItemsData}" Margin="3">
            <ListView.View>
                <GridView>
                    <GridViewColumn Width="Auto"  CellTemplate="{StaticResource col1}"  />
                    <GridViewColumn Width="Auto" Header="Time" CellTemplate="{StaticResource col2}" />
                    <GridViewColumn Width="700" Header="Message" CellTemplate="{StaticResource col3}" />
                </GridView>
            </ListView.View>
            <ListView.ContextMenu>
                <ContextMenu>
                    <MenuItem Command="{Binding DoCopySelectedLine}"                               
                              Header="Copy selected line to clipboard">
                        <MenuItem.Icon>
                            <Image Stretch="UniformToFill" Width="16" Height="16"  Source="images/CopyHS.png" HorizontalAlignment="Center" VerticalAlignment="Center" />
                        </MenuItem.Icon>
                    </MenuItem>
                    <MenuItem Command="{Binding DoCopyAllLines}" Header="Copy all lines to clipboard">
                        <MenuItem.Icon>
                            <Image Stretch="UniformToFill" Width="16" Height="16" Source="images/copy.png" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                        </MenuItem.Icon>
                    </MenuItem>
                    <MenuItem Command="{Binding DoClearList}" Header="Clear list">
                        <MenuItem.Icon>
                            <Image Stretch="UniformToFill" Width="16" Height="16" Source="images/delete.png" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                        </MenuItem.Icon>
                    </MenuItem>
                </ContextMenu>
            </ListView.ContextMenu>
        </ListView>
    </Grid>
</UserControl>
